﻿using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace TKT.Lifter.CIM.Lifter.Gui.Monitor.Panels
{

    /// <summary>
    /// 设置渐变色背景控件；
    /// </summary>
    public class GradientPanel : Panel
    {
        private Color exColor1 = Color.Lime;
        [Category("EX属性")]
        [DefaultValue(typeof(Color), "Lime")]
        public Color EXColor1
        {
            get => exColor1;
            set { exColor1 = value; Invalidate(); }
        }

        private Color exColor2 = Color.Blue;
        [Category("EX属性")]
        [DefaultValue(typeof(Color), "Blue")]
        public Color EXColor2
        {
            get => exColor2;
            set { exColor2 = value; Invalidate(); }
        }

        private float exAngle = 45f;
        [Category("EX属性")]
        [DefaultValue(typeof(float), "45")]
        public float EXAngle
        {
            get => exAngle;
            set { exAngle = value; Invalidate(); }
        }

        public GradientPanel()
        {
            DoubleBuffered = true;
        }


        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, exColor1, exColor2, exAngle);
            e.Graphics.FillRectangle(brush, ClientRectangle);
        }
    }
}
